package SecondWeek;

import java.util.Scanner;

public class Monday {
    // DP35 【模板】二维前缀和 (牛客)
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();
        //从下标1开始进行存数据，所以在基础上增加一位
        int[][] arr = new int[n + 1][m + 1];
        long[][] dp = new long[n + 1][m + 1];
        //对于数据的输入
        for (int i = 1;i <= n;i++) {
            for(int j = 1;j <= m;j++) {
                arr[i][j] = in.nextInt();
            }
        }
        //对于dp二维数组的处理
        for (int i = 1;i <= n;i++) {
            for (int j = 1;j <= m;j++) {
                //把整个要求的dp位置的i和j对应的位置的数据，分成四份
                // 要求的位置从1,1到i,j对应的值 =
                dp[i][j] = dp[i][j - 1] + dp[i - 1][j] + arr[i][j] - dp[i - 1][j - 1];
            }
        }

        while(q > 0) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            System.out.println((dp[x2][y2] - dp[x2][y1 - 1] -
                    dp[x1 - 1][y2] + dp[x1 - 1][y1 - 1]));
            q--;
        }
    }

    // DP34 【模板】前缀和 (牛客)(一维)
    public static void main1(String[] args) {
        //前缀和
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        // 创建n+1长度的数组，为了是其访问从1开始
        int[] arr = new int[n + 1];
        // 创建n+1长度的 前缀和 数组
        long[] dp = new long[n + 1];

        //对数组赋值 从下标1开始
        for (int i = 1;i <= n;i++) {
            arr[i] = in.nextInt();
        }
        //对前缀和数组dp进行预处理，下标对应的值是从1-i个arr数组的和，也就是dp[i-1]+arr[i]
        //例如 arr[0,1,2,4]
        //     dp[0,1,3,7]
        for (int i = 1;i <= n;i++) {
            dp[i] = dp[i - 1] + arr[i];
        }

        //查询q次
        while (q > 0) {
            int l = in.nextInt();
            int r = in.nextInt();
            //这里返回的值是dp[r] - dp[l - 1]
            //假如访问的是2-3，就是 7 - 1 = 6；arr[3] + arr[2] = 4 + 2 = 6
            System.out.println(dp[r] - dp[l - 1]);
            q--;
        }
    }
}
